package leecode

func reverseOddLevels(root *TreeNode) *TreeNode {
	var dfs func(left *TreeNode, right *TreeNode, isOddNum bool)
	dfs = func(left *TreeNode, right *TreeNode, isOddNum bool) {
		if left == nil || right == nil {
			//当左节点或者为空递归结束
			return
		}
		if isOddNum {
			left.Val, right.Val = right.Val, left.Val
		}
		dfs(left.Left, right.Right, !isOddNum)
		dfs(left.Right, right.Left, !isOddNum)
	}
	dfs(root.Left, root.Right, true)
	return root
}
